package cn.dlc.com.system.config.swagger;

import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @Author: dlc
 * @Date: 2021/12/6 - 14:48
 * swagger配置类
 */
// swagger3.0.0的配置
// @EnableOpenApi
@Configuration
// swagger2的配置   @EnableSwagger2（2.9.2版本）
 @EnableSwagger2
// 开发环境下生成对应的接口文件，非开发环境不生成，访问的时候会报错
@Profile(value = {"dev"})
public class SwaggerConfig {

    @Bean
    public Docket createRestApi() {
        // 如果使用3.0的话需要使用 DocumentationType.OAS_30
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                // 指定扫描路径
                .apis(RequestHandlerSelectors.basePackage("cn.dlc.com"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("接口文档")
                .description("enterprise接口文档")
                .contact(new Contact("dlc", null, null))
                .version("1.0")
                .build();
    }
}
